var Public = {
	init: function() {
		this.submitCode();
		this.getCode();
		this.showDiv();
		this.showCenter();
		//显示详情pc
		$(".js-hover").hover(function() {
				$(".js-hide").show();
			}, function() {
				$(".js-hide").hide();
			})
			//关闭tips
		$(".js-close").click(function() {
				$(".js-queen").hide();
			})
			//显示隐藏详情移动端
		$(".js-open").click( function() {
			if ($(this).html() == "收起") {
				$(".js-span span:gt(1)").hide();
				$(this).html("展开");
			} else {
				$(".js-span span:gt(1)").show();
				$(this).html("收起");
			}
		});
		var _this =this;
       $("#bank_submitb2c").click(function(){
       		_this.showCenter();
       });
       //关闭弹窗
       $(".js-close-add").click(function(){
       		$(".bg_b2c,.js-popwin").hide();
       		$(".js-error").html("");
       })
	},
	
	regs: {
		mobile: /^1[3|4|5|7|8][0-9]\d{8}$/,
		email: /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/,
		telphone: /(^[0-9]{3,4}\-[0-9]{3,8}$)|(^[0-9]{3,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)|(^0{0,1}13[0-9]{9}$)/,
		numberReg: /^\d+$/
	},
	checkTel: function(obj) {
		var reg1 = Public.regs.mobile;
		var telVal = $(obj).val();
		telVal = $.trim(telVal);
		if (telVal.length <= 0) {
			$(".js-error").html("手机号码不能为空");
			return;
		} else if (!reg1.test(telVal)) {
			$(".js-error").html("手机号码格式错误");
			return;
		} else {
			return true;

		}
	},
	checkCode: function(obj) {
		var codeVal = $(obj).val();
		codeVal = $.trim(codeVal);
		if (codeVal.length <= 0) {
			$(".js-error").html("验证码不能为空");
			return;
		} else {
			return true;

		}
	},
	//检测验证码
	submitCode: function() {
		var _this = this;
		$(".js-button").click( function() {
			$(".js-error").html("");
			if (_this.checkTel(".js-tel")&&_this.checkCode(".js-code")) {
				var mobile = $(".js-tel").val();
				mobile= $.trim(mobile);
				var mobileVerifyCode = $(".js-code").val();
				mobileVerifyCode = $.trim(mobileVerifyCode);
				$("#mobile_form").val(mobile);
				$("#mobileVerifyCode").val(mobileVerifyCode);
				var submitFormId = $("#submitFormId").val();
				$("#"+submitFormId).submit();
				$('#mobile_form').val('');
				$('#mobileVerifyCode').val('');
				var b2c_paygate = $('#b2c_paygate').val();
				$(".bg_b2c").hide();
				$("#js-popwintwo").hide();
				if('b2c_paygate'==b2c_paygate){
					openDialog();
				}
			}
		});
	},
	getCode: function() {
		var _this = this;
		$(".js-getcode").click(function() {
			$(".js-error").html("");
			if(_this.checkTel(".js-tel")){
				var mobile = $(".js-tel").val();
				mobile= $.trim(mobile);
				var orderKey = $("#orderKey").val();
				orderKey= $.trim(orderKey);
				var orderInfo = $("#orderInfo").val();
				orderInfo= $.trim(orderInfo);
				var isReceivablePaymentInput = $("#isReceivablePaymentInput").val();
				isReceivablePaymentInput= $.trim(isReceivablePaymentInput);
				var url= $("#url").val();
				url=$.trim(url);
				$.post(url,{mobile:mobile,orderKey:orderKey,orderInfo:orderInfo,isReceivablePayment:isReceivablePaymentInput},function(result){
					var data = eval("("+result+")");
						if(0==data.status){
							alert("获取验证码成功!");
						}else if(1==data.status){
							alert("验证码已发送!");
						}else if(2==data.status){
							alert("手机号输入次数超限!");
							$(".vericodeuse").attr("disabled","disabled");
						}else{
							alert("获取验证码失败!");
						}
						var i=60;
						var intval = setInterval(function(){
						if(0 < i){
							$(".js-getcode").html(i + "秒后重新获取");
							i--;
							$(".js-getcode").attr("disabled", true);
							$(".js-getcode").css("background-color","#c2c2c2");
						}else{
							$(".js-getcode").attr("disabled", false);
							$(".js-getcode").html("获取验证码");
							$(".js-getcode").css("background-color","#2a87e4");
							
							clearInterval(intval);
						}
						},1000);
				});
				
			};
		})
	},

	//隐藏展示
	showDiv: function() {
		var span = $(".js-span").find("span");
		if (span.length > 3) {
			$(".js-span span:gt(1)").hide();
		}
	},
	
	//弹窗显示居中
 	showCenter :function(){
 		var ObjWin = document.getElementById("js-popwintwo");
			 if(ObjWin !=null){
				var ObjH = ObjWin.clientHeight;
				var ObjW = ObjWin.clientWidth;
				ObjWin.style.marginTop = -ObjH/2 +"px";
				ObjWin.style.marginLeft = -ObjW/2 +"px";
			}
 		}

}
$(function() {
	Public.init();
})